import orderData from "@/utils/orderData.json";
import { createUniqueString } from "@/utils";

const orderDataStore = defineStore("order-data", {
  state: () => ({
    orderData: [],
    saleOrderData: [],
    seriesData: [],
    attrsData: [],
    computeData: [],
    offerData: [],
    columns: [],
    saleInfo: {
      customerName: '',
      PartnerBrand: '',
      deliveryTime: '',
    },
    currentSaleRow: {},
    customerInfo: [],
    orderTakerInfo: [],
    businessmanInfo: [],
    brandInfo: [],
  }),
  actions: {
    setOrderData(data) {
      this.orderData = data
    },
    setSaleOrderData(data) {
      this.saleOrderData = data
    },
    setSeriesData(data) {
      this.seriesData = data
    },
    setAttrsData(data) {
      this.attrsData = data
    },
    setComputeData(data) {
      this.computeData = data
    },
    setOfferData(data) {
      this.offerData = data
    },
    setColumns(data) {
      this.columns = data
    },
    setSaleInfo(data) {
      this.saleInfo = data
    },
    setCurrentSaleRow(data) {
      this.currentSaleRow = data
    },
    initData() {
      this.orderData.forEach((item) => {
        item.id = createUniqueString();
        item.submited = false
        if (!item.Picture) item.Picture = "";
      });
      this.customerInfo[0] = {
        name: "红云仓",
        brand: "非常好品牌",
        code: "2323AA",
        phone: "187272336252",
        tel: "0579121233",
        fax: "0579121287",
        agentBrand: "生弗思",
        province: "天津市",
        city: "天津市",
        area: "和平区",
        addressDetail: "",
        habit: "",
        remark: "",
        orderTaker: "",
        businessman: "",
        businessLicense: "",
        active: true,
        alarm: false,
      };
      this.customerInfo.forEach((item) => {
        item.address = `${item.province},${item.city},${item.area}`;
        item.recipient = item.name;
      });
      this.orderTakerInfo[0] = {
        orderTaker: "接单员一号",
        customers: "2323AA",
      };
      this.businessmanInfo[0] = {
        businessman: "业务员一号",
        customers: "2323AA",
      };
      this.brandInfo = [
        {
          brandName: "白皮包装不贴商标",
          LOGO: "",
          sort: 0,
        },
        {
          brandName: "艺嘉林",
          LOGO: "",
          sort: 1,
        },
        {
          brandName: "福喜旺来",
          LOGO: "",
          sort: 2,
        },
        {
          brandName: "奢帝泥",
          LOGO: "",
          sort: 3,
        },
      ];
    },
    getOrderDataSlice({ pageNum = 1, pageSize = 10 }) {
      return this.orderData.slice((pageNum - 1) * pageSize, pageNum * pageSize);
    },
  },
});

export default orderDataStore;
